<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');
require('../include/class/pagination.php');

if (!$pay_member) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;
if ((isset($_GET['PId'])) && ($_GET['PId'] != "" && $_GET['action'] == 'del')) {
    if(MEMBER_PAID === (int)$_SESSION['MM_UserGroup']) {
	    $check_sql = "select add_user from petlostfound where PId=".$_GET['PId'];
	    $check_sql_query = $db->query($check_sql);
	    $check_sql_row = $db->fetch($check_sql_query);
	    if((int)$check_sql_row['add_user'] !== (int)$_SESSION['MM_Username_id']){
		    die('<div style="text-align:center">You have no permission to delete this pet...</div>');
	    }
    }
    $deleteSQL = sprintf("DELETE FROM petlostfound WHERE PId=%s",
                      GetSQLValueString($_GET['PId'], "int"));

    $db->query($deleteSQL);
}

include('AdminPanel.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="50%" border="0" align="center" cellpadding="5" cellspacing="0" class="table_border_grey" style="margin-top:10px;">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td width="100">照片</td>
    <td width="80">分类</td>
    <td width="80">品种</td>
    <td width="100">捡到/走失</td>
    <td width="260">捡到/走失地点</td>
  </tr>
  
  <?php
    if(MEMBER_PAID === (int)$_SESSION['MM_UserGroup']) {
    	$where = " and add_user=".$_SESSION['MM_Username_id']." ";
    }
    else {
    	$where = "";
    }
    $sql = "SELECT * FROM petlostfound where 1 ".$where." order by PId DESC";
	$res = $db->query($sql);
	$num = $db->num($res);
	if($num > 0) {
		$pagination = new Pagination($num, PAGICATION_RECORD_COUNT_NEWS, $_GET['page'], PAGINATION_DELTA);
		$sql = $sql." limit ".$pagination->begin.",".$pagination->end;
		$res = $db->query($sql);
		while($row = $db->fetch($res)) {
    ?>
    <tr>
      
      <td> <label>
          <input type="button" name="button" id="button" value="Delete" onclick="if(confirm('Are you sure to delete this?')){window.location.href='<?php echo $_SERVER['PHP_SELF']?>?action=del&PId=<?php echo $row['PId']; ?>'}"/>
        </label>
      </td>
      <td><label><a href="EditPetLostFound.php?PId=<?php echo $row['PId'] ?>">Edit...
        </a>
      </label></td>
      <td><a href="ShowDetailPetLostFoundInfo.php?PId=<?php echo $row['PId']; ?>"><img src="<?php echo IMAGES_PET_FOLDER.$row['PPhoto_thumb']; ?>" border="0" class="img_border"></a></td>
      <td><a href="ShowDetailPetLostFoundInfo.php?PId=<?php echo $row['PId']; ?>"><?php echo getPetType($row['PType']); ?></a>&nbsp; </td>
      <td><?php echo $row['PVariety']; ?>&nbsp; </td>
      <td><?php echo getLostType($row['PIsLost']); ?>&nbsp; </td>
      <td><?php echo $row['PPlace']; ?>&nbsp; </td>
    </tr>
    <?php
		}
	}
	else {
		die('<div align="center">You have not added any pet lost and found info.</div>');
	}
	?>
	<tr>
    <td colspan="7">
	    <?php
		if($num > PAGICATION_RECORD_COUNT_NEWS) {
			echo $pagination->paginationString;
		}
		?>
	</td>
  </tr>
</table>
<br />
</body>
</html>